﻿using System;
using System.Collections.Generic;
using Moq;

namespace WpfApplication1.TaskModule
{
    internal class TaskItemsRepositoryMock : Mock<ITaskItemsRepository>
    {
        public event EventHandler DeleteHandler;
        public event EventHandler SaveHandler;

        public TaskItemsRepositoryMock()
            : base(MockBehavior.Default)
        {
            Setup(i => i.Tasks).Returns(new List<TaskItem> {new TaskItem(), new TaskItem()});

            Setup(i => i.Remove(null)).Callback(OnDelete);

            Setup(i => i.SaveChanges()).Callback(OnSave);

            Setup(i => i.HasUnsavedChanges()).Returns(true);
        }

        public void OnDelete()
        {
            if (DeleteHandler!=null)
            {
                DeleteHandler(this, null);
            }
        }

        public void OnSave()
        {
            if (SaveHandler != null)
            {
                SaveHandler(this, null);
            }
        }
    }
}